package com.sgb.kjwl.view.ui.activity.enterprise;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.viewpager.widget.ViewPager;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;
import com.google.android.material.tabs.TabLayout;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityQuoteDetailBinding;
import com.sgb.kjwl.di.enterprise.DaggerEnterpriseComponent;
import com.sgb.kjwl.di.enterprise.EnterpriseModule;
import com.sgb.kjwl.model.entity.enterprise.EpQuoteEntity;
import com.sgb.kjwl.model.entity.enterprise.QuestionEnyiy;
import com.sgb.kjwl.model.entity.enterprise.SecerTitleEntity;
import com.sgb.kjwl.utils.ActivityJump;
import com.sgb.kjwl.utils.DialogFunction;
import com.sgb.kjwl.utils.DialogHelper;
import com.sgb.kjwl.utils.PointUtils;
import com.swgk.core.util.UserOperating;
import com.swgk.core.event.EventConstant;
import com.sgb.kjwl.view.event.LoginEvent;
import com.sgb.kjwl.view.event.MemberEvent;
import com.sgb.kjwl.view.ui.activity.manage.WebsiteInfoActivity;
import com.sgb.kjwl.view.ui.activity.self.publish.GetPositionActivity;
import com.sgb.kjwl.view.ui.activity.self.userInfo.VerificationCodeLoginActivity;
import com.sgb.kjwl.view.ui.adapter.enterprise.EpQuoteAdapter;
import com.sgb.kjwl.view.ui.adapter.enterprise.TextViewBindingAdapter;
import com.sgb.kjwl.view.ui.fragment.enterprise.ServiceDetailDealedFragment;
import com.sgb.kjwl.view.ui.fragment.enterprise.ServiceDetailDescribeFragment;
import com.sgb.link.view.widget.ExpandedTextView;
import com.sgb.kjwl.view.widget.enterprise.ServiceNodePopWindow;
import com.sgb.kjwl.view.widget.enterprise.ServiceProSkuPopWindow;
import com.sgb.kjwl.viewmodel.enterprise.ProfessionalQuoteDetailModel;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.customview.ItemInputTextView;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;
import com.swgk.core.recyclerview.adapter.SlidingFragmentPagerAdapter;
import com.swgk.core.recyclerview.entity.BaseAreaEntity;
import com.swgk.core.util.ClickUtils;
import com.swgk.core.util.DateUtils;
import com.swgk.core.util.MToast;
import com.swgk.core.util.SharedPreferenceUtil;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

public class ProfessionalQuoteDetailActivity extends AppActivity implements ItemInputTextView.OnWholeItemClickListener {
    @Inject
    ProfessionalQuoteDetailModel viewModel;

    private ActivityQuoteDetailBinding binding;

    long id;
    EpQuoteEntity epQuoteEntity;
    RequestOptions mOptionsPerson;
    RequestOptions personOptions;
    RequestOptions teamOptions;
    private String mTag;
    private String mId;
    private int statusGZ = 0;//0未关注
    private boolean isTeam = false;//当前是团队
    private String dataId = "";

    private EpQuoteAdapter epQuoteAdapter;
    private ServiceNodePopWindow serviceNodePopWindow;
    private ServiceProSkuPopWindow serviceProSkuPopWindow;

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerEnterpriseComponent.builder().appComponent(appComponent)
                .enterpriseModule(new EnterpriseModule(this))
                .build()
                .inject(this);
    }

    public static void start(Context context, long id) {
        Intent intent = new Intent();
        intent.setClass(context, ProfessionalQuoteDetailActivity.class);
        intent.putExtra("id", id);
        context.startActivity(intent);
    }


    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(this, R.layout.activity_quote_detail);
        binding.actionBar.setTitle("服务详情");
        binding.llReport.setOnClickListener(this);
        binding.llHanxun.setOnClickListener(this);
        binding.llFocus.setOnClickListener(this);
        binding.llEnter.setOnClickListener(this);
        binding.tvXiaDan.setOnClickListener(this);
        binding.llJiaoliu.setOnClickListener(this);
        binding.llJiameng.setOnClickListener(this);
        binding.llXunjia.setOnClickListener(this);
        binding.itemTvPrj.setOnWholeItemClickListener(this);
        binding.itemTvNode.setOnWholeItemClickListener(this);
        binding.itemTvPrj.setContentTextEnd();

        mOptionsPerson = new RequestOptions().placeholder(R.mipmap.shop_image_new_round)//图片加载出来前，显示的图片
                .fallback(R.mipmap.shop_image_new_round) //url为空的时候,显示的图片
                .error(R.mipmap.shop_image_new_round);//图片加载失败后，显示的图片

        personOptions = new RequestOptions().placeholder(R.mipmap.morentu_person)//图片加载出来前，显示的图片
                .fallback(R.mipmap.morentu_person) //url为空的时候,显示的图片
                .error(R.mipmap.morentu_person);//图片加载失败后，显示的图片

        teamOptions = new RequestOptions().placeholder(R.mipmap.morentu_tuandui)//图片加载出来前，显示的图片
                .fallback(R.mipmap.morentu_tuandui) //url为空的时候,显示的图片
                .error(R.mipmap.morentu_tuandui);//图片加载失败后，显示的图片
        binding.recyclerView.setLoadingMoreEnabled(false);
        binding.recyclerView.setPullRefreshEnabled(false);


        binding.recyclerView.setLayoutManager(new LinearLayoutManager(this));
        epQuoteAdapter = new EpQuoteAdapter(getActivity(), null, false);
        binding.recyclerView.setAdapter(epQuoteAdapter);

        epQuoteAdapter.setOnItemClick(new AdapterOnItemClick<EpQuoteEntity>() {
            @Override
            public void onItemClick(EpQuoteEntity epQuoteEntity, int position) {
                ProfessionalQuoteDetailActivity.start(getActivity(), Long.parseLong(epQuoteEntity.getId()));
//                    finish();
            }
        });
        epQuoteAdapter.OnCallPhone((num, name) -> {
            if (DialogHelper.checkLogin()) {
                DialogHelper.showDialog(getActivity(), "确认呼叫", name + ":" + num, "确定", new DialogFunction() {
                    @Override
                    public void normalRoundDialog() {
                        ActivityJump.jumpToPhone(getActivity(), num);
                    }
                });
            } else {
                DialogHelper.showLoginDialogNew(this, EventConstant.EVENT_PROFESSIONAL_QUOTE_FRG_JUMP, "温馨提示", "登录后可拨打电话,去登录", "登录");
            }
        });

        binding.tvLookmore.setOnClickListener(view -> {
//            if(!ActivityUtils.isActivityExistsInStack(ProfessionalQuoteActivity.class)) {
//
//            }
            SecerTitleEntity entity = new SecerTitleEntity();
            if (epQuoteEntity != null) {
                if (!TextUtils.isEmpty(epQuoteEntity.getServiceClass())) {
                    entity.setCategoryFirstId(Long.parseLong(epQuoteEntity.getServiceClass()));
                }
                if (!TextUtils.isEmpty(epQuoteEntity.getFirstCategoryName())) {
                    entity.setCategoryFirstName(epQuoteEntity.getFirstCategoryName());
                }
                if (!TextUtils.isEmpty(epQuoteEntity.getServiceCategory())) {
                    entity.setCategorySecondId(Long.parseLong(epQuoteEntity.getServiceCategory()));
                }
                if (!TextUtils.isEmpty(epQuoteEntity.getSecondCategoryName())) {
                    entity.setCategorySecondName(epQuoteEntity.getSecondCategoryName());
                }
                if (!TextUtils.isEmpty(epQuoteEntity.getServiceItem())) {
                    entity.setCategorySecondId(Long.parseLong(epQuoteEntity.getServiceItem()));
                }
                if (!TextUtils.isEmpty(epQuoteEntity.getItemName())) {
                    entity.setCategorySecondName(epQuoteEntity.getItemName());
                }
            }
            ProfessionalQuoteActivity.start(this, entity);
//            }
//            finish();
        });
        serviceNodePopWindow = new ServiceNodePopWindow(this);
        serviceNodePopWindow.setBgView(binding.grayLayout);


        serviceProSkuPopWindow = new ServiceProSkuPopWindow(this);
        serviceProSkuPopWindow.setBgView(binding.grayLayout);
        serviceProSkuPopWindow.onPrice(new ServiceProSkuPopWindow.IPrice() {
            @Override
            public void getSelectPrice(String price) {
                if ("".equals(price))
                    return;
                binding.tvPrice.setText("议价".equals(price) ? price : TextViewBindingAdapter.setMoneyForRMB("￥" + PointUtils.price(Double.valueOf(price))));
            }

            @Override
            public void setSelectName(String content) {
                binding.itemTvPrj.setContent(content);
            }
        });
    }

    @Override
    protected void init() {
        id = getIntent().getLongExtra("id", 0);
        getDetail();

        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEvent(MemberEvent event) {
        if (event.getMessageTag() == EventConstant.EVENT_REPORT_INQUIRE_FINISH) {
            getDetail();
        }
    }

    private void getDetail() {
        viewModel.getData(id);
        viewModel.getAttentionStatus(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.USER_NO, ""), 7, String.valueOf(id));
    }

    public void showQuoteDetail(EpQuoteEntity epQuoteEntity) {
        this.epQuoteEntity = epQuoteEntity;
        binding.setViewModel(epQuoteEntity);
        isTeam = epQuoteEntity.getPublishType() == 2;
        //有无服务节点
        if (epQuoteEntity.getServiceProcesses() != null && epQuoteEntity.getServiceProcesses().size() != 0) {
            serviceNodePopWindow.setData(epQuoteEntity.getServiceProcesses());
        } else {
            binding.itemTvNode.setVisibility(View.GONE);
        }
        //有无服务项目
        if (!TextUtils.isEmpty(epQuoteEntity.getProjectClassificationJson())) {
//            binding.tvPrice.setText(!epQuoteEntity.getDomesticCompaniesPrice().equals("-1") ? TextViewBindingAdapter.setMoneyForRMB("￥" + PointUtils.price(Double.valueOf(epQuoteEntity.getDomesticCompaniesPrice()))) : "议价");
            serviceProSkuPopWindow.setData(viewModel.serviceProToBean(epQuoteEntity.getProjectClassificationJson()), viewModel.servicePriceToBean(epQuoteEntity.getOtherQualificationPrices()));
        } else {
            binding.tvPrice.setText(epQuoteEntity.getPrice() >= 0 ? TextViewBindingAdapter.setMoneyForRMB("￥" + PointUtils.price(epQuoteEntity.getPrice())) : "议价");
            binding.itemTvPrj.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(epQuoteEntity.getDomesticCompaniesPrice()))
            if (!epQuoteEntity.getStatus().equals("1")) {
                binding.bidLayout.setVisibility(View.GONE);
                binding.bidLayout.setAlpha(0.5f);
                binding.llJiaoliu.setClickable(false);
                binding.llReport.setClickable(false);
                binding.llHanxun.setClickable(false);
                binding.llFocus.setClickable(false);
            } else {
                binding.bidLayout.setVisibility(View.VISIBLE);
                binding.bidLayout.setAlpha(1);
                binding.llJiaoliu.setClickable(true);
                binding.llReport.setClickable(true);
                binding.llHanxun.setClickable(true);
                binding.llFocus.setClickable(true);
            }
        if (!TextUtils.isEmpty(epQuoteEntity.getServiceClass())) {
            viewModel.getRecomendListdata(epQuoteEntity.getServiceClass(), epQuoteEntity.getId() + "");
        }

        if (!epQuoteEntity.getStatus().equals("1")) {
            binding.llJiaoliu.setVisibility(View.GONE);
            binding.llData.setVisibility(View.GONE);
            binding.llServicetypeno.setVisibility(View.VISIBLE);
            return;
        }

        binding.llServicetypeno.setVisibility(View.GONE);
        binding.llJiaoliu.setVisibility(View.VISIBLE);
        binding.llData.setVisibility(View.VISIBLE);

        String city = epQuoteEntity.getServiceCitys();

        try {
            ArrayList<BaseAreaEntity> cityList = jsonToArrayList(city, BaseAreaEntity.class);
            StringBuilder stringBuilder = new StringBuilder();
            for (BaseAreaEntity entity : cityList) {
                stringBuilder.append(entity.getName()).append("/");
            }
            stringBuilder.toString();
            String cityShow = stringBuilder.toString().substring(0, stringBuilder.toString().length() - 1);
            binding.tvServiceCityValue.setText(cityShow);
        } catch (Exception e) {
            e.printStackTrace();
        }

        if (epQuoteEntity.getItemName() == null || epQuoteEntity.getItemName().equals("")) {
            binding.tvServiceProValue.setText("/");
        } else {
            binding.tvServiceProValue.setText(epQuoteEntity.getItemName());
        }

        if (epQuoteEntity.getSecondCategoryName() == null || epQuoteEntity.getSecondCategoryName().equals("")) {
            binding.tvServiceTypeValue.setText("/");
        } else {
            binding.tvServiceTypeValue.setText(epQuoteEntity.getSecondCategoryName());
        }

        if (epQuoteEntity.getFirstCategoryName() == null || epQuoteEntity.getFirstCategoryName().equals("")) {
            binding.tvServiceCateValue.setText("/");
        } else {
            binding.tvServiceCateValue.setText(epQuoteEntity.getFirstCategoryName());
        }

        setImage(epQuoteEntity.getPublishType(), binding.userName, epQuoteEntity.getCompanyNo(), epQuoteEntity.getTeamId(), epQuoteEntity.getHeadImage(), epQuoteEntity.getCompanyLogo(), epQuoteEntity.getLogo(), binding.rivTouxiang, binding.ivLogo
                , epQuoteEntity.getUserRealName(), epQuoteEntity.getCompanyName(), epQuoteEntity.getRealName(), binding.tvEnterpriseName, epQuoteEntity.getCompanyServiceType(), epQuoteEntity.getBusinessType(), binding.tvType, epQuoteEntity.getUserAuthTime()
                , epQuoteEntity.getCompanyAuthTime(), epQuoteEntity.getTeamAuthTime(), binding.tvTimeInto, "个人认证", epQuoteEntity.getUserIsAuth(), "企业认证", epQuoteEntity.getCompanyIsAuth(), "团队认证", epQuoteEntity.getTeamAuth(), binding.tvTypeAuthen,
                epQuoteEntity.getAdress(), binding.tvPath, binding.ivAddressLat, epQuoteEntity.getLatitude(), epQuoteEntity.getLongitude());

        showTabLayout();
        new ExpandedTextView().showTextPick(binding.tvServiceCityValue, binding.tvBasicExpand);

    }


    //展示常见问题
    public void showQuestionListdata(List<QuestionEnyiy> list) {
        if (list.size() > 0) {
            binding.linQuestion.setVisibility(View.VISIBLE);
            for (QuestionEnyiy questionEnyiy : list) {
                //添加常见问题
                final long id = questionEnyiy.getId();
                binding.linQuestion.addView(new QuestionView(this, questionEnyiy.getTitle(), questionEnyiy.getAbstractContent(), view -> {
                    QuestionDetailActivity.startactivity(this, id + "");
                }));

            }
        } else {
            binding.linQuestion.setVisibility(View.GONE);
        }
    }

    //展示推荐数据
    public void showRecommend(List<EpQuoteEntity> list) {


        if (list != null && list.size() > 0) {
            epQuoteAdapter.setDatas(list);
            binding.linRecomend.setVisibility(View.VISIBLE);
            binding.tvLookmore.setVisibility(View.VISIBLE);

        } else {
            binding.linRecomend.setVisibility(View.GONE);
            binding.tvLookmore.setVisibility(View.GONE);
        }
    }

    /**
     * @param json
     * @param clazz
     * @return
     */
    public static <T> ArrayList<T> jsonToArrayList(String json, Class<T> clazz) {
        Type type = new TypeToken<ArrayList<JsonObject>>() {
        }.getType();
        ArrayList<T> arrayList = new ArrayList<>();
        try {
            ArrayList<JsonObject> jsonObjects = new Gson().fromJson(json, type);

            for (JsonObject jsonObject : jsonObjects) {
                arrayList.add(new Gson().fromJson(jsonObject, clazz));
            }
        } catch (Exception e) {

        }

        return arrayList;
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ll_jiaoliu://联系商家
                if (!ClickUtils.isDoubleClick()) {
                    if (DialogHelper.checkLogin()) {
                        DialogHelper.showDialog(ProfessionalQuoteDetailActivity.this,
                                "确认呼叫",
                                epQuoteEntity.getContact() + ":" + epQuoteEntity.getContactPhone(),
                                "确定", new DialogFunction() {
                                    @Override
                                    public void normalRoundDialog() {
                                        ActivityJump.jumpToPhone(ProfessionalQuoteDetailActivity.this, epQuoteEntity.getContactPhone());
                                    }
                                });
                    } else {
                        VerificationCodeLoginActivity.start(ProfessionalQuoteDetailActivity.this);
                    }
                }
                break;
            case R.id.ll_enter://进入企业
                if (!ClickUtils.isDoubleClick()) {
                    if (!mTag.equals("没有店铺")) {
                        if (mId.equals("企业")) {
//                            ActivityJump.jumpToActivity(this, ShopInfoForCompanyTradesActivity.class, Pair.create("id", mTag + ""));
                            WebsiteInfoActivity.start(this, mTag, 1);
                        } else {
//                            ActivityJump.jumpToActivity(getActivity(), ProfessionalTeamDetailActivity.class, Pair.create("id", Long.parseLong(mTag)));
                        }
                    } else {
                        MToast.showToast(this, "暂无个人店铺");
                    }
                }
                break;
            case R.id.ll_report://举报
                if (!UserOperating.getInstance().isLogged()) {
                    VerificationCodeLoginActivity.start(this);
                } else {
                    if (UserOperating.getInstance().isTeam() || isTeam) {
                        DialogHelper.showSingleDialog(this, "温馨提示", "该功能正在开发中，敬请期待~", "确定", true, new DialogFunction() {
                            @Override
                            public void normalRoundDialog() {

                            }
                        });
                    } else {
                        if (epQuoteEntity.getPublishType() == 1) {
                            ReportEnterpriseActivity.start(this, String.valueOf(epQuoteEntity.getId()), epQuoteEntity.getName(), "3", "1",
                                    epQuoteEntity.getCompanyName(), epQuoteEntity.getNo(), "", "", "", "");
                        } else if (epQuoteEntity.getPublishType() == 2) {
                            ReportEnterpriseActivity.start(this, String.valueOf(epQuoteEntity.getId()), epQuoteEntity.getName(), "3", "1",
                                    "", "", epQuoteEntity.getRealName(), epQuoteEntity.getTeamNo(), "", "");
                        }
                    }
                }
                break;
            case R.id.ll_focus://关注
                if (!UserOperating.getInstance().isLogged()) {
                    VerificationCodeLoginActivity.start(this);
                } else {
                    if (SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LOGIN_PHONE, "").equals(epQuoteEntity.getUserAccount())) {
                        MToast.showToast(this, "不能关注当前账号下发布的内容！");
                        return;
                    }
                    Map<String, Object> map = new HashMap<>();
                    map.put("id", id);
                    map.put("dataId", dataId);
                    map.put("type", 7);
                    map.put("attentionNot", statusGZ);
                    map.put("attentionTime", System.currentTimeMillis());
                    map.put("attentionNo", SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.USER_NO, ""));
                    viewModel.focusService(map, statusGZ);
                }
                break;
            case R.id.ll_hanxun://函询
                // 转让 详情函询
                if (!UserOperating.getInstance().isLogged()) {
                    VerificationCodeLoginActivity.start(this);
                } else {
                    if (UserOperating.getInstance().isTeam() || isTeam) {
//                        DialogHelper.showSingleDialog(this, "温馨提示", "该功能正在开发中，敬请期待~", "确定", true, new DialogFunction() {
//                            @Override
//                            public void normalRoundDialog() {
//
//                            }
//                        });
                        MToast.showLongToast(this,"功能开发中，敬请期待！");
                    } else {
                        EnterpriseInquireByLetterActivity.start(this, "3", "1",
                                String.valueOf(epQuoteEntity.getId()), epQuoteEntity.getName(), epQuoteEntity.getCompanyName(), epQuoteEntity.getNo(), "", "");
                    }
                }
                break;
            case R.id.tv_xia_dan:
            case R.id.ll_jiameng:
            case R.id.ll_xunjia:
                MToast.showToast(this, "功能开发中，敬请期待！");
                break;
        }
    }

    public void setTvIsGz(int isGz) {
        //标是否关注
        if (isGz == 1) {
            statusGZ = 0;
        } else {
            statusGZ = 1;
        }
        updateUserFocusBg();
    }

    private void updateUserFocusBg() {
        //标是否关注
        if (statusGZ == 0) {
            Drawable drawable = getResources().getDrawable(R.mipmap.icon_follow_gray);
            binding.ivFocus.setImageDrawable(drawable);
            binding.tvUserFocus.setText("关注");
            binding.tvUserFocus.setTextColor(getResources().getColor(R.color.color_666666));
        } else {
            Drawable drawable = getResources().getDrawable(R.mipmap.icon_follow_red);
            binding.ivFocus.setImageDrawable(drawable);
            binding.tvUserFocus.setText("已关注");
            binding.tvUserFocus.setTextColor(getResources().getColor(R.color.color_main));
        }
    }

    public void setDataId(String dataId) {
        this.dataId = dataId;
    }

    /**
     * 服务详情内
     */
    private void showTabLayout() {
        binding.tablayout2.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                LinearLayout linearLayout = (LinearLayout) LayoutInflater.from(ProfessionalQuoteDetailActivity.this).inflate(R.layout.item_textview_4, null);
                TextView selectTextView = linearLayout.findViewById(R.id.tab_item_textview);
                selectTextView.setText(tab.getText());
                tab.setCustomView(linearLayout);
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
                tab.setCustomView(null);
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
        String[] titles = {"服务描述", "成交案例"};
        ArrayList<Fragment> mFragments = new ArrayList<>();
        mFragments.add(ServiceDetailDescribeFragment.newInstance(epQuoteEntity));
        mFragments.add(ServiceDetailDealedFragment.newInstance(Long.parseLong(epQuoteEntity.getId())));
        SlidingFragmentPagerAdapter pagerAdapter = new SlidingFragmentPagerAdapter(getSupportFragmentManager(), mFragments, titles);
        binding.vpProfessionalTeamDetail.setCurrentItem(0);
        binding.vpProfessionalTeamDetail.setOffscreenPageLimit(titles.length);
        binding.vpProfessionalTeamDetail.setAdapter(pagerAdapter);
        binding.tablayout2.setupWithViewPager(binding.vpProfessionalTeamDetail);
        binding.vpProfessionalTeamDetail.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(binding.tablayout2));
        binding.vpProfessionalTeamDetail.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                binding.vpProfessionalTeamDetail.resetHeight(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        binding.tablayout2.getTabAt(0).select();
    }

    /**
     * 提供子fragment调用方法，解决listview高度不自适应出现多余空白
     */
    public void setChildObjectForPosition(View view, int poistion) {
        binding.vpProfessionalTeamDetail.setObjectForPosition(view, poistion);
    }

    /**
     * 提供子fragment调用方法，解决listview高度不自适应出现多余空白
     */
    public void setScroll(boolean is) {
        binding.displayView.requestDisallowInterceptTouchEvent(is);
    }

    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
    public void onEvent(LoginEvent event) {
        if (event.getMessageTag() == EventConstant.EVENT_PROFESSIONAL_QUOTE_JUMP) {
            viewModel.getData(id);
            viewModel.getAttentionStatus(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.USER_NO, ""), 7, String.valueOf(id));
        }
    }

    @SuppressLint("SetTextI18n")
    public void setImage(int publishType, ImageView imageArrow, String companyId, String teamId
            , String urlPerson, String urlCompany, String urlTeam, ImageView imageViewPerson, ImageView imageViewCompany
            , String namePerson, String nameCompany, String nameTeam, TextView nameTextView
            , String businessTypeCompany, String businessTypeTeam, TextView businessTypeTextView
            , long authTimePerson, long authTimeCompany, long authTimeTeam, TextView authTimeTextView
            , String authStatusPerson, int personAuth, String authStatusCompany, int companyAuth, String authStatusTeam, int teamAuth, TextView authStatusTextView
            , String path, TextView tv_path, ImageView imagepath, String Latitude, String Longitude

    ) {
        String url, name, businessType, authTime, authStatus, pathstring;
        RequestOptions optionsP;
        ImageView imageView;
        if (publishType == 0) {
            optionsP = personOptions;
            url = urlPerson;
            imageArrow.setVisibility(View.GONE);
            name = namePerson;
            businessTypeTextView.setVisibility(View.INVISIBLE);
            businessType = "";
            authTime = DateUtils.timestampToDate(0);
            authStatus = authStatusPerson;
            if (personAuth == 1) {
                authStatusTextView.setVisibility(View.VISIBLE);
            } else {
                authStatusTextView.setVisibility(View.GONE);
            }
            imageView = imageViewPerson;
            imageViewCompany.setVisibility(View.GONE);
            imageViewPerson.setVisibility(View.VISIBLE);
            pathstring = "所在地区：" + (TextUtils.isEmpty(path) ? "/" : path);
            mTag = "没有店铺";
        } else if (publishType == 1) {
            optionsP = mOptionsPerson;
            url = urlCompany;
            imageArrow.setVisibility(View.VISIBLE);
            businessTypeTextView.setVisibility(View.VISIBLE);
            name = nameCompany;
            businessType = "经营类型：" + (TextUtils.isEmpty(businessTypeCompany) ? "/" : businessTypeCompany);
            authTime = DateUtils.timestampToDate(authTimeCompany);
            authStatus = authStatusCompany;
            if (companyAuth == 1) {
                authStatusTextView.setVisibility(View.VISIBLE);
            } else {
                authStatusTextView.setVisibility(View.GONE);
            }
            imageView = imageViewCompany;
            imageViewCompany.setVisibility(View.VISIBLE);
            imageViewPerson.setVisibility(View.GONE);
            mTag = companyId;
            mId = "企业";
            if (name != null && !name.equals("")) {
                imageArrow.setVisibility(View.VISIBLE);
            } else {
                imageArrow.setVisibility(View.GONE);
            }
            pathstring = "经营地址：" + (TextUtils.isEmpty(path) ? "/" : path);
        } else {
            optionsP = teamOptions;
            url = urlTeam;
            imageArrow.setVisibility(View.GONE);
            businessTypeTextView.setVisibility(View.VISIBLE);
            name = nameTeam;
            businessType = "经营类型：" + (TextUtils.isEmpty(businessTypeTeam) ? "/" : businessTypeTeam);
            authTime = DateUtils.timestampToDate(authTimeTeam);
            authStatus = authStatusTeam;
            if (teamAuth == 2) {
                authStatusTextView.setVisibility(View.VISIBLE);
            } else {
                authStatusTextView.setVisibility(View.GONE);
            }
            imageView = imageViewPerson;
            imageViewCompany.setVisibility(View.GONE);
            imageViewPerson.setVisibility(View.VISIBLE);
            mTag = teamId;
            mId = "团队";
            authTimeTextView.setVisibility(View.VISIBLE);
            if (name != null && !name.equals("")) {
                imageArrow.setVisibility(View.GONE);
            } else {
                imageArrow.setVisibility(View.GONE);
            }
            pathstring = "所在地区：" + (TextUtils.isEmpty(path) ? "/" : path);
        }
        tv_path.setText(pathstring);
        if (!TextUtils.isEmpty(path)) {
            if (!TextUtils.isEmpty(Latitude) && !TextUtils.isEmpty(Longitude)) {
                imagepath.setVisibility(View.VISIBLE);
                final String namepath = name;
                imagepath.setOnClickListener((view) -> {
                    Double lat = 0.0, lng = 0.0;
                    if (!TextUtils.isEmpty(Latitude)) {
                        lat = Double.valueOf(Latitude);
                    }
                    if (!TextUtils.isEmpty(Longitude)) {
                        lng = Double.valueOf(Longitude);
                    }
                    GetPositionActivity.start(getActivity(), lng, lat, path, namepath);
                });
            } else {
                imagepath.setVisibility(View.GONE);
            }
        } else {
            imagepath.setVisibility(View.GONE);
        }

        optionsP.transform(new CircleCrop());

        Glide.with(this).load(url).apply(optionsP).into(imageView);
        nameTextView.setText(name);
        businessTypeTextView.setText(businessType.equals("经营类型:null") ? "" : businessType);
        authTimeTextView.setText(authTime + "入驻");
        authStatusTextView.setText(authStatus);
        if (authTime.equals("1970-01-01")) {
            authTimeTextView.setVisibility(View.GONE);
        }
    }

    @Override
    public void OnWholeItemClick(View view) {
        switch (view.getId()) {
            case R.id.item_tv_prj:
                serviceProSkuPopWindow.showDownPopwindow(binding.grayLayout, true);
                break;
            case R.id.item_tv_node:
                serviceNodePopWindow.showDownPopwindow(binding.grayLayout, true);
                break;
        }
    }
}


